package m202406.d08;

import java.util.ArrayList;
import java.util.List;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/8 21:49
 */
public class Q6 {

    public static void main(String[] args) {
        Q6 q6 = new Q6();
        q6.convert("AB", 1);
    }


    //字符串处理
    public String convert(String s, int numRows) {
        if (numRows == 1) {
            return s;
        }
        StringBuilder[] sbs = new StringBuilder[numRows];
        boolean flag = true;
        for (int i = 0, row = 0; i < s.length(); i++) {
            if (sbs[row] == null) {
                sbs[row] = new StringBuilder();
            }
            sbs[row].append(s.charAt(i));
            if (row >= numRows - 1) {
                flag = false;
            }
            if (row <= 0) {
                flag = true;
            }
            if (flag) {
                row++;
            } else {
                row--;
            }
        }
        StringBuilder rs = new StringBuilder();
        for (StringBuilder sb : sbs) {
            rs.append(sb == null ? "" : sb);
        }
        return rs.toString();
    }
}
